package rr_test_client;

public class TCMessageUtil {

	TestClient testClient;
	
	public TCMessageUtil(TestClient testClient) {
		this.testClient = testClient;
	}

	public void processMessage(String message) {
		if (message.contains("identification")) {
			handleIdentificationMsg(message);
		}
		
		if (message.contains("connectiontest")) {
			handleConnectionTestMsg();
		}
		
		if (message.contains("update")) {
			handleUpdateMsg(message);
		}
		
		if (message.contains("phrase")) {
			
		}
		
		if (message.contains("error")) {
			
		}
	}
	
	public String makePlayRequestMsg() {
		String playRequestMsg = "<playrequest><sender>" + testClient.playerId + "</sender></playrequest>";
		return playRequestMsg;
	}
	
	public String makePhraseMsg() {
		String phraseMsg = "";
		
		
		return phraseMsg;
	}	
	
	public String makeResultMsg(String score) {
		String resultMsg = "";
		
		
		return resultMsg;
	}
	
	public String makeQuitRequestMsg() {
		String quitRequestMsg = "<quitrequest><sender>" + testClient.playerId + "</sender></quitrequest>";
		return quitRequestMsg;
	}

	public void handleIdentificationMsg(String message) {
		int playerId = Integer.parseInt(String.valueOf(message.charAt(26)));
		testClient.playerId = playerId;
	}
	
	public void handleConnectionTestMsg() {
		String connectionTestMsg = "<connectiontest><playerid>" + testClient.playerId + "</playerid></connectiontest>";
		testClient.sendText(connectionTestMsg);
	}

	public void handleUpdateMsg (String message) {
		
		
		
	}
	
	public void handlePhraseMsg(String message) {
		
		
		
	}
	
	public void handleErrorMsg(String message) {
		
		
		
	}
	
}
